package com.school.empsys.service.impl;

import com.school.empsys.constants.LeavePermitStatus;
import com.school.empsys.mapper.EmpLeavePermitMapper;
import com.school.empsys.model.EmpLeavePermit;
import com.school.empsys.service.EmpLeavePermitService;
import com.school.empsys.utils.UserUtil;
import org.apache.commons.lang3.time.DateUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class EmpLeavePermitServiceImpl implements EmpLeavePermitService {

    @Autowired
    EmpLeavePermitMapper empLeavePermitMapper;


    @Override
    public int count(Map<String, Object> params) {
        return empLeavePermitMapper.count(params);
    }

    @Override
    public List<EmpLeavePermit> list(Map<String, Object> params, Integer offset, Integer limit) {
        return empLeavePermitMapper.list(params, offset, limit);
    }

    @Override
    public void save(EmpLeavePermit param) {
        param.setCreateTime(new Date());
        param.setUpdateTime(new Date());
        param.setStatus(LeavePermitStatus.SUBMIT.getName());
        param.setUserId(UserUtil.getCurrentUser().getId().intValue());
        empLeavePermitMapper.insert(param);
    }

    @Override
    public EmpLeavePermit findOne(Integer id) {
        return empLeavePermitMapper.selectByPrimaryKey(id);
    }

    @Override
    public void aduit(EmpLeavePermit param) {
        param.setUpdateTime(new Date());
        param.setApprover(UserUtil.getCurrentUser().getId().intValue());
        empLeavePermitMapper.updateByPrimaryKeySelective(param);
    }

}
